#ifndef SUBJECTMANAGERWIDGET_H
#define SUBJECTMANAGERWIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QComboBox>
#include <QSpinBox>
#include <QPushButton>
#include <QTableWidget>
#include <QGroupBox>
#include <QCheckBox>
#include <QRadioButton>
#include <QScrollArea>
#include <QStackedWidget>
#include <QMap>

class SubjectManagerWidget : public QWidget {
    Q_OBJECT
public:
    explicit SubjectManagerWidget(QWidget *parent = nullptr);
signals:
    void subjectAdded(const QString &name, const QString &gender, int age, const QMap<QString, QString> &optionalData);
public slots:
    void reloadSubjectList(const QList<QVariantList> &subjects);
private slots:
    void onAddButtonClicked();
    void onOptionalButtonClicked();

private:
    // 必填信息控件
    QLineEdit *m_nameEdit;
    QComboBox *m_genderCombo;
    QSpinBox *m_ageSpin;
    QPushButton *m_addButton;
    QPushButton *m_optionalButton;

    // 选填信息控件
    QWidget *m_optionalWidget;
    bool m_optionalExpanded;

    // 选填信息分类
    QMap<QString, QWidget*> m_categoryWidgets;
    QMap<QString, QMap<QString, QWidget*>> m_optionalFields;

    // 被试列表显示
    QTableWidget *m_table;

    // 初始化UI组件
    void setupRequiredFields();
    void setupOptionalFields();
    QWidget* createCategoryWidget(const QString &title, const QStringList &fields);

    // 获取所有选填数据
    QMap<QString, QString> collectOptionalData();
};

#endif // SUBJECTMANAGERWIDGET_H
